
//  author 白珅瑞
//  contcat 15903482433
// src/api/materials.js
import axios from "axios";

// 获取物料列表
export const getMaterials = (queryForm) => {
  const params = new URLSearchParams(
    Object.entries(queryForm).filter(([, value]) => value !== "") // 只保留非空字段
  );
  return axios.get(`/api/materials?${params.toString()}`);
};

// 获取单个物料
export const getMaterialById = (id) => {
  return axios.get(`/api/materials/${id}`);
};

// 创建物料
export const createMaterial = (material) => {
  return axios.post("/api/materials", material);
};

// 更新物料
export const updateMaterial = (material) => {
  return axios.put(`/api/materials`, material);
};

// 删除物料
export const deleteMaterial = (id, version) => {
  return axios.delete(`/api/materials/${id}/${version}`);
};

// 导出物料
export const exportMaterials = (queryForm) => {
  const params = new URLSearchParams(
    Object.entries(queryForm).filter(([, value]) => value !== "") // 只保留非空字段
  );
  return axios({
    method: "GET",
    url: `/api/materials/export?${params.toString()}`,
    responseType: "blob",
  });
};
